package com.example.yskjproject.adapter;


import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.yskjproject.R;
import com.example.yskjproject.http.Urls;
import com.example.yskjproject.http.callback.JsonCallback;
import com.example.yskjproject.model.LzyResponse;
import com.example.yskjproject.model.OrderListModel;
import com.example.yskjproject.view.dialog.OrderDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import es.dmoral.toasty.Toasty;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * OrderAdapter
 * <p>  收入订单
 * 作者：zx
 * 创建时间：2024/5/3
 */
public class SROrderAdapter extends BaseQuickAdapter<OrderListModel.OrderListBean, BaseViewHolder> {

    private static final int TYPE_NORMAL = 0;
    private static final int TYPE_FIRST = 1;

    private int titleType;

    private Context context;

    public SROrderAdapter(Context context, @Nullable List<OrderListModel.OrderListBean> data) {
        super(data);
        this.context =context;
    }

    public void setTitleType(int titleType){
        this.titleType = titleType;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_FIRST;
        }
        return TYPE_NORMAL;
    }




    @Override
    protected BaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        switch (viewType) {
            case TYPE_FIRST:
                View view1 = inflater.inflate(R.layout.item_top2_order, parent, false);
                return new ViewHolder1(view1);
            case TYPE_NORMAL:
                View view = inflater.inflate(R.layout.item_order2, parent, false);
                return new ViewHolder2(view);
        }
        return null;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderListModel.OrderListBean item) {
        if (helper.getItemViewType() == TYPE_NORMAL) {
            helper.setText(R.id.order_num,item.getOrder_sn());
            helper.setText(R.id.student_name,item.getBuyer_user().getNick_name());
            helper.setText(R.id.courses_name,item.getCourse_info().getCourse_name());
            helper.setText(R.id.courses_time,item.getCreated_at());
            switch (item.getState()){//  订单状态，0待支付，1已取消，2已支付，3退款中，4退款成功
                case  0:
                    helper.setText(R.id.courses_state,"待支付");
                    break;
                case  1:
                    helper.setText(R.id.courses_state,"已取消");
                    break;
                case  2:
                    helper.setText(R.id.courses_state,"已支付");
                    break;
                case  3:
                    helper.setText(R.id.courses_state,"退款中");
                    break;
                case  4:
                    helper.setText(R.id.courses_state,"退款成功");
                    break;
            }
            helper.setText(R.id.courses_money,item.getPaid_price()/100  + "元");
            helper.setText(R.id.courses_actual_money,item.getDivided_amount()/100 + "元");
            if(item.getDivided_state() == 1){
                helper.setText(R.id.courses_actual_state,"冻结中");
            }else{
                helper.setText(R.id.courses_actual_state,"到账");
            }
            helper.getView(R.id.jl_refund).setOnClickListener( jltk ->{
                OrderDialog delectOrderDialog = new OrderDialog(context, item.getOrder_sn(), item.getUser_id(), "jltk");
                delectOrderDialog.show();
            });

        }
    }


    public static class ViewHolder1 extends BaseViewHolder {
        public ViewHolder1(View view) {
            super(view);
            // 初始化布局1的控件
        }
    }

    public static class ViewHolder2 extends BaseViewHolder {
        public ViewHolder2(View view) {
            super(view);
            // 初始化布局2的控件
        }
    }
}
